<?php
/**
 * 描述
 * Created by Paco
 * Date: 2018/10/5 Time: 11:45
 */

namespace App\Console\Commands\Elastic;


use App\Lib\Elasticsearch\Elasticsearch;
use Illuminate\Console\Command;

class Bank extends Command
{
    protected $signature = 'es:bank';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = '创建银行产品索引';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }


    /**
     * Execute the console command.
     *
     * @return mixed
     */
    public function handle()
    {
        $es = new Elasticsearch('bank_index');
        print_r($es->getMapping());
        //$this->createIndex($es);
        //$this->putMapping($es);

    }

    public function createIndex(Elasticsearch $es)
    {
        $rs = $es->create();
        print_r($rs);
    }


    public function putMapping(Elasticsearch $es)
    {
        $body = [
            'properties' => [
                'product_id' => [
                    'type' => 'integer'
                ],
                'logo' => [
                    'type' => 'keyword'
                ],
                'product_type' => [
                    'type' => 'integer'
                ],
                'service_type' => [
                    'type' => 'integer'
                ],
                'min_deposit' => [
                    'type' => 'integer'
                ],
                'max_deposit' => [
                    'type' => 'integer'
                ],
                'min_time_limit' => [
                    'type' => 'integer'
                ],
                'max_time_limit' => [
                    'type' => 'integer'
                ],
                'mortgage_type' => [
                    'type' => 'integer'
                ],
                'loan_time' => [
                    'type' => 'keyword'
                ],
                'title' => [
                    'type' => 'text',
                    'analyzer' => 'ik_max_word',
                    'search_analyzer' => 'ik_max_word',
                ],
                'city' => [
                    'type' => 'text',
                    'analyzer' => 'ik_max_word',
                    'search_analyzer' => 'ik_max_word',
                ],
            ]
        ];

        $rs = $es->mapping($body);
        print_r($rs);

    }
}